package cn.tristenstudy.blog.util;

import org.apache.commons.lang3.RandomStringUtils;
import org.apache.shiro.crypto.hash.Md5Hash;

/**
 * @author xichen1.li
 * @date 2020-12-25 11:54
 */
public class MD5Util {

    private static final String SALT = "fnwZWuaAePIr9UKSAAqd";

    /**
     * 生成盐值
     *
     * @return 盐值
     */
    public static String getSalt() {
        return RandomStringUtils.randomAlphanumeric(20);
    }

    public static String getPassword(String username, String password, String salt, int hashTimes) {
        Md5Hash md5Hash = new Md5Hash(password, username + SALT, hashTimes);
        return md5Hash.toString();
    }
}
